import {
	JSEncrypt
} from 'jsencrypt'
import {AES as crypto_aes,lib as crypto_lib,enc as crypto_enc} from 'crypto-js'
class RSA {
	constructor() {
		this.publicKey =
			'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCchMK0CagXK85JQpN1shThngF6F+pHobpacmg7Brj0ldjsQbx+8VTr1Ad2ir7ATwuUXGFNYOX3RHwJb8mjf6PLRYYY//7WhC1dyNAahzU1r1EjHBKAAwQhr0yRendCivJkY6x/pRIccizI1RrA9t+H9jEbyAco5ZYdMrjti77gDwIDAQAB';
	}
	encrypt(txt) {
		const encryptor = new JSEncrypt()
		encryptor.setPublicKey(this.publicKey) // 设置公钥
		return encryptor.encrypt(txt) // 对数据进行加密
	}
	decrypt(txt) {
		const encryptor = new JSEncrypt()
		encryptor.setPrivateKey(this.privateKey) // 设置私钥
		return encryptor.decrypt(txt) // 对数据进行解密
	}
}
class AES {
	
	constructor() {
		this.secretKey = ''
		this.iv = ''
	}
	generateSecretKey(){
		this.secretKey = crypto_lib.WordArray.random(16).toString();
		this.iv = crypto_lib.WordArray.random(16).toString();
	}
	encrypt(txt) {
		return crypto_aes.encrypt(txt, crypto_enc.Hex.parse(this.secretKey), {
		    iv: crypto_enc.Hex.parse(this.iv)
		}).toString();
	}
	
}
export {RSA,AES}